package model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class Junction {
	private List<Road> roads = new ArrayList<Road>();
	
	public void add(Road r){
		r.connect(this);
		roads.add(r);
	}
	
	public Collection<Road> getRoads(){
		return Collections.unmodifiableCollection(roads);
	}
	
	public boolean canReach(Junction j){
		for (Road r : roads) {
			if(r.isConnectedTo(j))
				return true;
		}
		return false;
	}
	
	public Set<Junction> getReachableJunctions(){
		Set<Junction> junctions = new HashSet<Junction>();
		for (Road r : roads) {
			junctions.add(r.getSideA());
			junctions.add(r.getSideB());
		}
		return junctions;
	}
}
